package com.tools.common.utils;

import android.content.Context;
import android.text.TextUtils;

import java.io.File;
import java.util.ArrayList;

public class FileUtils {

    public static final String REPO_DIR = "repo";

    public static ArrayList<File> getAllFilesInDir(final File dir) {
        if(dir == null || !dir.isDirectory() || !dir.canRead()) {
            return null;
        }

        ArrayList<File> list = new ArrayList<>();
        for(File f : dir.listFiles()) {
            if(f != null && f.isFile() && f.exists()) {
                list.add(f);
            }
        }

        return list;
    }

    public static final File getRepoDir(Context context) {
        if(context == null) return null;

        File dir = new File(context.getExternalFilesDir(null)
                + File.separator + REPO_DIR);

        if(!dir.exists()) {
            dir.mkdir();
        }

        return dir.exists() ? dir : null;
    }

}
